var express = require('express');
const { default: mongoose } = require('mongoose');
var router = express.Router();
var jwt = require('jsonwebtoken');
const { userModel } = require('../model/bjl_model')
router.get('/login', async (req, res) => {
	let data = await userModel.find()
	res.send({ data })
})
router.post('/login', async (req, res) => {
	let body = req.body
	console.log("Aaa",body);
	let [data] = await userModel.find({ "$and": [{ 'username': body.username }, { 'password': body.password }] }).exec()
	let token = "Bearer" + " " + jwt.sign({ username: body.username }, 'flag', { expiresIn: 10000 })

	if (data) {
		res.send({
			code: 200,
			msg: '登录成功',
			data,
			token
		})
	} else {
		res.send({
			code: 201,
			msg: '用户或者密码错误',
		})
	}

})
module.exports = router;